﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MiniStock.Client.UI.Models.CreateProductModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Create
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<script type="text/javascript">
    var tid;
    var cid;

    function checkresult() {
        $.post("../Event/Get?correlationId=" + cid, function (r, s) {
            switch (r.State) {
                case 0:
                    clearInterval(tid);
                    $("#result").html("Unknown event id: " + cid);
                    break;
                case 1:
                    // Processing
                    $("#result").html("processing...");
                    break;
                case 2:
                    // Success
                    clearInterval(tid);
                    $("#result").html(r.EntityHash);
                    $.post("Get?id=" + r.EntityHash, function (rr, ss) {
                        $("#result").html(rr);
                    });
                    break;
                case 3:
                    // Failure
                    clearInterval(tid);
                    $("#result").html("error");
                    break;
            }
        }, "json");
    }

    $(document).ready(function () {
        $("#submitBtn").click(function () {
            $("#result").html("posting message...");
            $.post("CreateProduct", {
                name: $("#Name").val(),
                productNumber: $("#ProductNumber").val()
            }, function (r, s) {
                cid = r;
                $("#result").html("polling for cid=" + cid);
                tid = setInterval(checkresult, 1000);
            });
        });


    });
</script>

<h2>Create Product</h2>

<%: Html.LabelFor(i => i.ProductNumber) %> <%: Html.TextBoxFor(i => i.ProductNumber)%><br />
<%: Html.LabelFor(i => i.Name) %> <%: Html.TextBoxFor(i => i.Name)%><br />


<div id="result">result</div>

<button id="submitBtn"></button>

</asp:Content>
